Skip to content

Don't translate default arguments as Option - #648

Merged
nunoplopes merged 5 commits into
Cpp2Rust:masterfrom
lucic71:68-fn-pointer-default-args
Nov 18, 2026
Merged

nunoplopes merged 5 commits into
Cpp2Rust:masterfrom
lucic71:68-fn-pointer-default-args

Conversation

@lucic71

@lucic71 lucic71 commented Nov 18, 2026

Copy link
Copy Markdown
Contributor

Master translates int add(int a, int b = 2) { return a + b; } as fn add(a: i32, b: Option<i32>) -> i32.

This breaks taking the address of functions with default arguments: expected 'fn add(a: i32, b: i32) -> i32', found 'fn add(a: i32, b: Option<i32>) -> i32'.

Drop the Option from the function signature and evaluate the default argument before entering the function. This is closer to what C++ does.

@nunoplopes
nunoplopes merged commit f614f07 into Cpp2Rust:master Nov 18, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants